(function (window) {
    var _parentCallback = null;
    var dragParent = {
        initParent: function (className, parentCallback) {
            addDragParent(document.getElementsByClassName(className));
            _parentCallback = parentCallback;
        }
    };
    var tools = {
        on: function (el, type, listener) {
            el.addEventListener(type, listener);
        },
        addClass: function (el, className) {
            el.classList.add(className);
        },
        removeClass: function (el, cls) {
            if (arguments.length < 2) {
                el.classList.remove(cls);
            }
            else {
                for (var i = 1, len = arguments.length; i < len; i++) {
                    el.classList.remove(arguments[i]);
                }
            }
        }
    };
    function addDragParent(nodeList) {
        var _len = nodeList.length;
        for (var i = 0; i < _len; i++) {
            var el = nodeList[i];
            tools.on(el, 'dragover', handleParentDragOver);
            tools.on(el, 'dragenter', handleParentDragEnter);
            tools.on(el, 'dragend', handleParentDragEnd);
            tools.on(el, 'dragleave', handleParentDragLeave);
            tools.on(el, 'drop', handleParentDrop);
        }
    }
    function handleParentDragOver(e) {
        e.preventDefault();
        if (e.stopPropagation) {
            e.stopPropagation();
        }
        return false;
    }
    function handleParentDragEnter(e) {
        e.preventDefault();
        if (e.stopPropagation) {
            e.stopPropagation();
        }
        return false;
    }
    function handleParentDragEnd(e) {
        e.preventDefault();
        if (e.stopPropagation) {
            e.stopPropagation();
        }
        return false;
    }
    function handleParentDragLeave(e) {
        e.preventDefault();
        if (e.stopPropagation) {
            e.stopPropagation();
        }
        return false;
    }
    function handleParentDrop(e) {
        var data = JSON.parse(e.dataTransfer.getData('text'));
        console.log(data);
        _parentCallback(data);
        e.preventDefault();
        if (e.stopPropagation) {
            e.stopPropagation();
        }
        return false;
    }
    window.dragParent = dragParent;
})(window);
